from selenium import webdriver
from time import sleep
from selenium.webdriver import ActionChains  # 控制动作的模块

# 建立浏览器对象
browser = webdriver.Chrome('D:\\资料\\第六个月\\chromedriver.exe')
browser.get('http://localhost:8080/login')
sleep(2)

# 填入用户名
browser.find_elements_by_tag_name('input')[1].send_keys('xiaobai')
sleep(2)

browser.find_elements_by_tag_name('input')[2].send_keys('123')
sleep(2)

# 定义拖动对象
button = browser.find_element_by_class_name('dv_handler')
box = browser.find_element_by_class_name('dv_text')

# 定义动作对象
action = ActionChains(browser)
action.click_and_hold(button).perform()
# 释放动作
action.reset_actions()

square_len = button.size.get('width')  # 获取按钮条长度
box_len = box.size.get('width')  # 获取按钮条长度

action.move_by_offset(box_len - square_len, 0).perform()  #拖动按钮条

sleep(1)

# 点击登陆按钮
browser.find_element_by_class_name('h-btn').click()

sleep(2)

browser.close()
